package com.superiron.scaffold.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;

/**
 * 版权所有 泰山信息技术有限公司
 *
 * @Author: 杨振国
 * @Date 2022/4/16 下午5:40
 */
@Slf4j
@Component
public class MqttMessageHandler implements MessageHandler {


    /**
     * Handle the given message.
     *
     * @param message the message to be handled
     * @throws MessagingException if the handler failed to process the message
     */
    @Override
    @ServiceActivator(inputChannel = "channel1")
    // 每个消费者对应一个handler实现
    public void handleMessage(Message<?> message) throws MessagingException {
        String payload = message.getPayload().toString();
        String topic = message.getHeaders().get("mqtt_receivedTopic").toString();
        log.info("topic:{}", topic);
        log.info("payload:{}", payload);
    }
}
